package com.anysoft.ui.activity.web;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.webkit.WebView;

import com.anysoft.base.BaseWebViewActivity;
import com.anysoft.config.AppConstant;
import com.anysoft.utils.ActivityCollector;
import com.anysoft.utils.NetWorkUtil;
import com.anysoft.utils.StringUtil;

import java.util.HashMap;

/**
 * Created by LiTingYao on 2018/7/7.
 * 二级页面通用
 */
public class SecondCommActivity extends BaseWebViewActivity {
    
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        String url = getIntent().getStringExtra("url");
        String titleName = getIntent().getStringExtra("titleName");
        title.setText(StringUtil.isEmpty(titleName) ? "" : titleName);
        if (StringUtil.isEmpty(url)) {
            return;
        }
        String token = (TextUtils.isEmpty(AppConstant.token)) ? "" : AppConstant.token;
        if (url.contains("?")) {
            if (url.endsWith("?")) {
                loadUrl = url + "token=" + token;
            } else {
                loadUrl = url + "&token=" + token;
            }
        } else {
            loadUrl = url + "?token=" + token;
        }
        
        if (NetWorkUtil.isConnect(this)) {
            setWebViewConfig(loadUrl);
        }
        
    }
    
    @Override
    protected void onResume() {
        super.onResume();
    }
    
    @Override
    protected void onPause() {
        super.onPause();
    }
    
    @Override
    public void onshouldOverrideUrlLoadingCallBack(WebView webview, String url, String params) {
        HashMap<String, String> urlMap = handleUrlParams(url);
        String titleName = urlMap.get("title");
        mIntent.putExtra("titleName", titleName);
        mIntent.putExtra("url", url);
        ActivityCollector.startTargetActivity(this, ThreeCommActivity.class, mIntent);
        
    }
    
    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
